﻿using QFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectSurvivor
{
    public class ExpUpgradeItem
    {

        public bool UpgradeFinish { get; set; } = false;

        public string key { get; private set; }

        public string Description => mDescriptionFactory(CurrentLevel.Value);

        public int MaxLevel { get; private set; }
        public BindableProperty<int>  CurrentLevel =new BindableProperty<int>(1);

        public BindableProperty<bool> Visible=new BindableProperty<bool>();
        private Func<int, string> mDescriptionFactory;


        public void Upgrade()
        {
            CurrentLevel.Value++;
            mOnUpgrade?.Invoke(this,CurrentLevel.Value);
            if (CurrentLevel.Value > 10)
            {
                UpgradeFinish = true;
            }
        }


  

        private Action<ExpUpgradeItem,int> mOnUpgrade;



        public ExpUpgradeItem WithKey(string key)
        {
            this.key = key;
            return this;
        }


        public ExpUpgradeItem WithDescription(Func<int,string> descriptionFactory) {

            mDescriptionFactory = descriptionFactory;
            return this;
        
        
        }

        public ExpUpgradeItem OnUpgrade(Action<ExpUpgradeItem,int> onUpgrade)
        {
            this.mOnUpgrade = onUpgrade;
            return this;
        }

    

        public ExpUpgradeItem WithMaxLevel(int maxLevel)
        {
            this.MaxLevel = maxLevel;
            return this;
        }
    }
}
